class Solution
{
public:
    int findChampion(vector<vector<int>> &grid)
    {
        int n = grid.size();
        vector<int> inDegrees(n, 0);
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < grid[i].size(); j++)
            {
                if (grid[i][j] == 1)
                {
                    inDegrees[j]++;
                }
            }
        }
        int zeroDegreeCount = 0;
        int champion = -1;
        for (int i = 0; i < n; i++)
        {
            if (inDegrees[i] == 0)
            {
                zeroDegreeCount++;
                champion = i;
            }
        }
        return zeroDegreeCount == 1 ? champion : -1;
    }
};